<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编码" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择订单类型" clearable>
          <el-option
            v-for="dict in dict.type.com_order_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单开始时间" prop="orderStartName">
        <el-date-picker clearable
          v-model="queryParams.orderStartName"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择订单开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="订单结束时间" prop="orderEndName">
        <el-date-picker clearable
          v-model="queryParams.orderEndName"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择订单结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="客户名称" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="companyUserName">
        <el-input
          v-model="queryParams.companyUserName"
          placeholder="请输入客户联系人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入客户联系人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付方式" prop="paymentType">
        <el-select v-model="queryParams.paymentType" placeholder="请选择支付方式" clearable>
          <el-option
            v-for="dict in dict.type.sys_pay_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态" clearable>
          <el-option
            v-for="dict in dict.type.com_order_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="员工姓名" prop="staffName">
        <el-input
          v-model="queryParams.staffName"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付流水号" prop="paymentCode">
        <el-input
          v-model="queryParams.paymentCode"
          placeholder="请输入支付流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['customer:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['customer:order:remove']"
        >批量删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="info"
            plain
            icon="el-icon-upload2"
            size="mini"
            @click="handleImport"
            v-hasPermi="['customer:order:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['customer:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单编码" align="center" prop="orderCode" />
      <el-table-column label="订单金额" align="center" prop="amount" />
      <el-table-column label="邮费" align="center" prop="postFee" />
      <el-table-column label="实付金额" align="center" prop="payment" />
      <el-table-column label="订单类型" align="center" prop="orderType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.com_order_type" :value="scope.row.orderType"/>
        </template>
      </el-table-column>
      <el-table-column label="客户名称" align="center" prop="customerName" />
      <el-table-column label="支付方式" align="center" prop="paymentType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_pay_status" :value="scope.row.paymentType"/>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.com_order_type" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="渠道名称" align="center" prop="channelName" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="支付流水号" align="center" prop="paymentCode" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row,scope.index)"
              v-hasPermi="['customer:order:query']"
          >详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit"  @click="handleUpdate(scope.row)"
                     v-hasPermi="['customer:order:edit']" >修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['customer:order:remove']" >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="updateopen" width="850px" append-to-body>
      <el-form :inline="true" class="demo-form-inline" ref="form" :model="form" :rules="rules" label-width="150px">
        <el-form-item label="订单编码" prop="orderCode">
          <el-input v-model="form.orderCode" placeholder="请输入订单编码" />
        </el-form-item>
        <el-form-item label="订单金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入订单金额" />
        </el-form-item>
        <el-form-item label="邮费" prop="postFee">
          <el-input v-model="form.postFee" placeholder="请输入邮费" />
        </el-form-item>
        <el-form-item label="实付金额" prop="payment">
          <el-input v-model="form.payment" placeholder="请输入实付金额" />
        </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
          <el-select v-model="form.orderType" placeholder="请选择订单类型">
            <el-option
              v-for="dict in dict.type.com_order_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单类型名称" prop="orderTypeName">
          <el-select v-model="form.orderTypeName" placeholder="请选择订单类型名称">
            <el-option
              v-for="dict in dict.type.com_order_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单开始时间" prop="orderStartName">
          <el-date-picker clearable
            v-model="form.orderStartName"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择订单开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="订单结束时间" prop="orderEndName">
          <el-date-picker clearable
            v-model="form.orderEndName"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择订单结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="客户id" prop="customerId">
          <el-input v-model="form.customerId" placeholder="请输入客户id" />
        </el-form-item>
        <el-form-item label="客户名称" prop="customerName">
          <el-input v-model="form.customerName" placeholder="请输入客户名称" />
        </el-form-item>
        <el-form-item label="客户联系人名称" prop="companyUserName">
          <el-input v-model="form.companyUserName" placeholder="请输入客户联系人名称" />
        </el-form-item>
        <el-form-item label="客户职务" prop="companyTitle">
          <el-input v-model="form.companyTitle" placeholder="请输入客户职务" />
        </el-form-item>
        <el-form-item label="客户联系人电话" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入客户联系人电话" />
        </el-form-item>
        <el-form-item label="支付方式" prop="paymentType">
          <el-select v-model="form.paymentType" placeholder="请选择支付方式">
            <el-option
              v-for="dict in dict.type.sys_pay_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.com_order_type"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="员工id" prop="staffId">
          <el-input v-model="form.staffId" placeholder="请输入员工id" />
        </el-form-item>
        <el-form-item label="员工姓名" prop="staffName">
          <el-input v-model="form.staffName" placeholder="请输入员工姓名" />
        </el-form-item>
        <el-form-item label="渠道id" prop="channelId">
          <el-input v-model="form.channelId" placeholder="请输入渠道id" />
        </el-form-item>
        <el-form-item label="渠道代码" prop="channelCode">
          <el-input v-model="form.channelCode" placeholder="请输入渠道代码" />
        </el-form-item>
        <el-form-item label="上级渠道id" prop="parentChannelId">
          <el-input v-model="form.parentChannelId" placeholder="请输入上级渠道id" />
        </el-form-item>
        <el-form-item label="渠道名称" prop="channelName">
          <el-input v-model="form.channelName" placeholder="请输入渠道名称" />
        </el-form-item>
        <el-form-item label="产品id" prop="productId">
          <el-input v-model="form.productId" placeholder="请输入产品id" />
        </el-form-item>
        <el-form-item label="产品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="支付流水号" prop="paymentCode">
          <el-input v-model="form.paymentCode" placeholder="请输入支付流水号" />
        </el-form-item>
        <el-form-item label="是否开发票" prop="isInvoiceFlag">
          <el-radio-group v-model="form.isInvoiceFlag">
            <el-radio
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="发票号" prop="invoiceNo">
          <el-input v-model="form.invoiceNo" placeholder="请输入发票号" />
        </el-form-item>
        <el-form-item label="发票金额" prop="invoiceAmount">
          <el-input v-model="form.invoiceAmount" placeholder="请输入发票金额" />
        </el-form-item>
        <el-form-item label="是否快递" prop="isPostFlag">
          <el-input v-model="form.isPostFlag" placeholder="请输入是否快递" />
        </el-form-item>
        <el-form-item label="快递号" prop="postNo">
          <el-input v-model="form.postNo" placeholder="请输入快递号" />
        </el-form-item>
        <el-form-item label="快递开始时间" prop="postStartDate">
          <el-date-picker clearable
            v-model="form.postStartDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择快递开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="快递结束时间" prop="postEndDate">
          <el-date-picker clearable
            v-model="form.postEndDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择快递结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 订单详情对话框 -->
    <el-dialog :title="title" :visible.sync="detailopen" width="850px" append-to-body>
      <el-form :inline="true" class="demo-form-inline" ref="form" :model="form" :rules="rules" label-width="150px">
                        <el-form-item label="订单编码" prop="orderCode">
                          <el-input v-model="form.orderCode" placeholder="请输入订单编码" />
                        </el-form-item>
                        <el-form-item label="订单金额" prop="amount">
                          <el-input v-model="form.amount" placeholder="请输入订单金额" />
                        </el-form-item>
                        <el-form-item label="邮费" prop="postFee">
                          <el-input v-model="form.postFee" placeholder="请输入邮费" />
                        </el-form-item>
                        <el-form-item label="实付金额" prop="payment">
                          <el-input v-model="form.payment" placeholder="请输入实付金额" />
                        </el-form-item>
                        <el-form-item label="订单类型" prop="orderType">
                          <el-select v-model="form.orderType" placeholder="请选择订单类型">
                            <el-option
                                v-for="dict in dict.type.com_order_type"
                                :key="dict.value"
                                :label="dict.label"
                                :value="dict.value"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="订单类型名称" prop="orderTypeName">
                          <el-select v-model="form.orderTypeName" placeholder="请选择订单类型名称">
                            <el-option
                                v-for="dict in dict.type.com_order_type"
                                :key="dict.value"
                                :label="dict.label"
                                :value="dict.value"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="订单开始时间" prop="orderStartName">
                          <el-date-picker clearable
                                          v-model="form.orderStartName"
                                          type="date"
                                          value-format="yyyy-MM-dd"
                                          placeholder="请选择订单开始时间">
                          </el-date-picker>
                        </el-form-item>
                        <el-form-item label="订单结束时间" prop="orderEndName">
                          <el-date-picker clearable
                                          v-model="form.orderEndName"
                                          type="date"
                                          value-format="yyyy-MM-dd"
                                          placeholder="请选择订单结束时间">
                          </el-date-picker>
                        </el-form-item>
                        <el-form-item label="客户id" prop="customerId">
                          <el-input v-model="form.customerId" placeholder="请输入客户id" />
                        </el-form-item>
                        <el-form-item label="客户名称" prop="customerName">
                          <el-input v-model="form.customerName" placeholder="请输入客户名称" />
                        </el-form-item>
                        <el-form-item label="客户联系人名称" prop="companyUserName">
                          <el-input v-model="form.companyUserName" placeholder="请输入客户联系人名称" />
                        </el-form-item>
                        <el-form-item label="客户职务" prop="companyTitle">
                          <el-input v-model="form.companyTitle" placeholder="请输入客户职务" />
                        </el-form-item>
                        <el-form-item label="客户联系人电话" prop="mobile">
                          <el-input v-model="form.mobile" placeholder="请输入客户联系人电话" />
                        </el-form-item>
                        <el-form-item label="支付方式" prop="paymentType">
                          <el-select v-model="form.paymentType" placeholder="请选择支付方式">
                            <el-option
                                v-for="dict in dict.type.sys_pay_status"
                                :key="dict.value"
                                :label="dict.label"
                                :value="dict.value"
                            ></el-option>
                          </el-select>
                        </el-form-item>
                        <el-form-item label="订单状态" prop="status">
                          <el-radio-group v-model="form.status">
                            <el-radio
                                v-for="dict in dict.type.com_order_type"
                                :key="dict.value"
                                :label="dict.value"
                            >{{dict.label}}</el-radio>
                          </el-radio-group>
                        </el-form-item>
                        <el-form-item label="员工id" prop="staffId">
                          <el-input v-model="form.staffId" placeholder="请输入员工id" />
                        </el-form-item>
                        <el-form-item label="员工姓名" prop="staffName">
                          <el-input v-model="form.staffName" placeholder="请输入员工姓名" />
                        </el-form-item>
                        <el-form-item label="渠道id" prop="channelId">
                          <el-input v-model="form.channelId" placeholder="请输入渠道id" />
                        </el-form-item>
                        <el-form-item label="渠道代码" prop="channelCode">
                          <el-input v-model="form.channelCode" placeholder="请输入渠道代码" />
                        </el-form-item>
                        <el-form-item label="上级渠道id" prop="parentChannelId">
                          <el-input v-model="form.parentChannelId" placeholder="请输入上级渠道id" />
                        </el-form-item>
                        <el-form-item label="渠道名称" prop="channelName">
                          <el-input v-model="form.channelName" placeholder="请输入渠道名称" />
                        </el-form-item>
                        <el-form-item label="产品id" prop="productId">
                          <el-input v-model="form.productId" placeholder="请输入产品id" />
                        </el-form-item>
                        <el-form-item label="产品编码" prop="productCode">
                          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
                        </el-form-item>
                        <el-form-item label="产品名称" prop="productName">
                          <el-input v-model="form.productName" placeholder="请输入产品名称" />
                        </el-form-item>
                        <el-form-item label="支付流水号" prop="paymentCode">
                          <el-input v-model="form.paymentCode" placeholder="请输入支付流水号" />
                        </el-form-item>
                        <el-form-item label="是否开发票" prop="isInvoiceFlag">
                          <el-radio-group v-model="form.isInvoiceFlag">
                            <el-radio
                                v-for="dict in dict.type.sys_yes_no"
                                :key="dict.value"
                                :label="dict.value"
                            >{{dict.label}}</el-radio>
                          </el-radio-group>
                        </el-form-item>
                        <el-form-item label="发票号" prop="invoiceNo">
                          <el-input v-model="form.invoiceNo" placeholder="请输入发票号" />
                        </el-form-item>
                        <el-form-item label="发票金额" prop="invoiceAmount">
                          <el-input v-model="form.invoiceAmount" placeholder="请输入发票金额" />
                        </el-form-item>
                        <el-form-item label="是否快递" prop="isPostFlag">
                          <el-input v-model="form.isPostFlag" placeholder="请输入是否快递" />
                        </el-form-item>
                        <el-form-item label="快递号" prop="postNo">
                          <el-input v-model="form.postNo" placeholder="请输入快递号" />
                        </el-form-item>
                        <el-form-item label="快递开始时间" prop="postStartDate">
                          <el-date-picker clearable
                                          v-model="form.postStartDate"
                                          type="date"
                                          value-format="yyyy-MM-dd"
                                          placeholder="请选择快递开始时间">
                          </el-date-picker>
                        </el-form-item>
                        <el-form-item label="快递结束时间" prop="postEndDate">
                          <el-date-picker clearable
                                          v-model="form.postEndDate"
                                          type="date"
                                          value-format="yyyy-MM-dd"
                                          placeholder="请选择快递结束时间">
                          </el-date-picker>
                        </el-form-item>
                        <el-form-item label="备注" prop="remark">
                          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
                        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="detailopen = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url + '?updateSupport=' + upload.updateSupport"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/customer/order";
import {getToken} from "@/utils/auth";

export default {
  name: "Order",
  dicts: ['com_order_type', 'sys_yes_no', 'sys_pay_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否详情显示弹出层
      detailopen: false
      ,
      // 是否修改新增显示弹出层
      updateopen: false
      ,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: null,
        amount: null,
        postFee: null,
        payment: null,
        orderType: null,
        orderTypeName: null,
        orderStartName: null,
        orderEndName: null,
        customerId: null,
        customerName: null,
        companyUserName: null,
        companyTitle: null,
        mobile: null,
        paymentType: null,
        status: null,
        staffId: null,
        staffName: null,
        channelId: null,
        channelCode: null,
        parentChannelId: null,
        channelName: null,
        productId: null,
        productCode: null,
        productName: null,
        paymentCode: null,
        isInvoiceFlag: null,
        invoiceNo: null,
        invoiceAmount: null,
        isPostFlag: null,
        postNo: null,
        postStartDate: null,
        postEndDate: null,
        postStatus: null,
        createDate: null,
        updateDate: null,
        isDeleted: null,
      },
      // 表单参数
      form: {},
      // 导入参数
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题（
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "customer/order/importData"
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.updateopen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderCode: null,
        amount: null,
        postFee: null,
        payment: null,
        orderType: null,
        orderTypeName: null,
        orderStartName: null,
        orderEndName: null,
        customerId: null,
        customerName: null,
        companyUserName: null,
        companyTitle: null,
        mobile: null,
        paymentType: null,
        status: null,
        staffId: null,
        staffName: null,
        channelId: null,
        channelCode: null,
        parentChannelId: null,
        channelName: null,
        productId: null,
        productCode: null,
        productName: null,
        paymentCode: null,
        isInvoiceFlag: null,
        invoiceNo: null,
        invoiceAmount: null,
        isPostFlag: null,
        postNo: null,
        postStartDate: null,
        postEndDate: null,
        postStatus: null,
        createDate: null,
        createBy: null,
        updateDate: null,
        updateBy: null,
        isDeleted: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.updateopen = true;
      this.title = "添加订单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.updateopen = true;
        this.title = "修改订单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.updateopen = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.updateopen = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除订单编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 详情按钮操作 */
    handleView(row) {
      this.detailopen = true;
      this.form = row;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('customer/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    },
/** 导入按钮操作 */
handleImport() {
  this.upload.title = "导入";
  this.upload.open = true;
},
/** 下载模板操作 */
importTemplate() {
  this.download('customer/order/importTemplate', {
  }, `customer_order_template.xlsx`)
},
// 文件上传中处理
handleFileUploadProgress(event, file, fileList) {
  this.upload.isUploading = true;
},
// 文件上传成功处理
handleFileSuccess(response, file, fileList) {
  this.upload.open = false;
  this.upload.isUploading = false;
  this.$refs.upload.clearFiles();
  this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
  this.getList();
},
// 提交上传文件
submitFileForm() {
  this.$refs.upload.submit();
}
  }
};
</script>
